﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConfigMeister
{
    public partial class LightBox : Form
    {
        public LightBox(Light mod)
        {
            InitializeComponent();

            textBox1.Text = mod.Name;

            numericUpDown9.Value =  (decimal)mod.Pos.X;
            numericUpDown10.Value = (decimal)mod.Pos.Y;
            numericUpDown11.Value = (decimal)mod.Pos.Z;

            numericUpDown14.Value = (decimal)mod.Dest.X;
            numericUpDown13.Value = (decimal)mod.Dest.Y;
            numericUpDown12.Value = (decimal)mod.Dest.Z;

            pictureBox2.BackColor = mod.Ambient;

            checkBox1.Checked = mod.Decay;

            numericUpDown3.Value = (decimal) mod.DecayInverseParam;
            numericUpDown4.Value = (decimal) mod.DecayInverseSqrParam;

            numericUpDown2.Value = (decimal) mod.AmbientCoef;
            numericUpDown1.Value = (decimal) mod.Multiplier;

            checkBox3.Checked = mod.CastShadow;

            radioButton1.Checked = mod.Targeted;
            radioButton2.Checked = mod.IsAmbient;
        }

        public Light Result
        {
            get
            {
                Light mod = new Light();

                mod.Name = textBox1.Text;

                mod.Pos.X = (double) numericUpDown9.Value;
                mod.Pos.Y = (double) numericUpDown10.Value;
                mod.Pos.Z = (double) numericUpDown11.Value;

                mod.Dest.X = (double) numericUpDown14.Value;
                mod.Dest.Y = (double) numericUpDown13.Value;
                mod.Dest.Z = (double) numericUpDown12.Value;

                mod.Ambient = pictureBox2.BackColor;

                mod.Decay = checkBox1.Checked;

                mod.DecayInverseParam = (double) numericUpDown3.Value;
                mod.DecayInverseSqrParam = (double) numericUpDown4.Value;

                mod.AmbientCoef = (double) numericUpDown2.Value;
                mod.Multiplier = (double) numericUpDown1.Value;

                mod.CastShadow = checkBox3.Checked;

                mod.Targeted = radioButton1.Checked;
                mod.IsAmbient = radioButton2.Checked;

                return mod;

            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            ColorDialog dialog = new ColorDialog { Color = pictureBox2.BackColor };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                pictureBox2.BackColor = dialog.Color;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text == "")
            {
                MessageBox.Show("Podaj jakąś nazwę dla światła", "Błąd");
                return;
            }
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}
